/*
 * This file is part of GuitarMaster.
 * 
 * GuitarMaster is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GuitarMaster is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.paris5.master2.guitarmaster.entity;

import com.paris5.master2.guitarmaster.bean.EcomCategory;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Leticia Mahamed, Alice Khammy, mourad nedjahi, Saliou Mamadou Barry
 */
@Entity
@Table(name = "category")
public class Category implements Serializable {
    
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id_category")
    private Integer idCategory;
    
    @Size(max = 65535)
    @Column(name = "title", length = 65535)
    private String title;
    
    @Size(max = 65535)
    @Column(name = "description", length = 65535)
    private String description;
    
    @JoinColumn(name = "cat_id_category", referencedColumnName = "id_category")
    @ManyToOne
    private Category catIdCategory;

    public Category() {
    }
    
    public Category(EcomCategory ec) {
        idCategory=ec.getIdCategory();
        title=ec.getTitle();
        description=ec.getDescription();
        if(ec!=null&& ec.getParent()!=null){
            catIdCategory=new Category();
            catIdCategory.setIdCategory(ec.getParent().getIdCategory());
        }
    }
    
    public EcomCategory getEcomCategory(){
        EcomCategory ec = new EcomCategory();
        ec.setTitle(title);
        ec.setDescription(description);
        ec.setIdCategory(idCategory);
        if(catIdCategory!=null){
            ec.setParent(catIdCategory.getEcomCategory());
        }
        return ec;
    }
    
    public Category(Integer idCategory) {
        this.idCategory = idCategory;
    }

    public Integer getIdCategory() {
        return idCategory;
    }

    public void setIdCategory(Integer idCategory) {
        this.idCategory = idCategory;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Category getCatIdCategory() {
        return catIdCategory;
    }

    public void setCatIdCategory(Category catIdCategory) {
        this.catIdCategory = catIdCategory;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCategory != null ? idCategory.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Category)) {
            return false;
        }
        Category other = (Category) object;
        if ((this.idCategory == null && other.idCategory != null) || (this.idCategory != null && !this.idCategory.equals(other.idCategory))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.paris5.master2.guitarmaster.entity.Category[ idCategory=" + idCategory + " ]";
    }
}
